<?php
/**
 * 
 * Stores data from all input methods in one place.
 * @author Jakub Szajna <qba307@gmail.com>
 *
 */
class Input {
	
    /**
     * POST data
     * @var array
     */
    static private $_post;
    /**
     * SERVER data
     * @var array
     */
    static private $_server;
    /**
     * GET data
     * @var array
     */
    static private $_get;
    
    /** 
     * Initiates object.
     * @param object $r Router object
     */
    static function init( Router $r ) {
        self::$_get = $r -> getUriParams();
        self::$_post = $_POST;
        self::$_server = $_SERVER;
        $_GET = null;
        $_POST = null;
        $_SERVER = null;
    }
    
    /**
     * Get data from GET method.
     * @param string $key
     * @param bool $xss_clean If set to true, class will return xss cleaned data.
     */
    static function get( $key, $xss_clean = false ) {
        $get = isset( self::$_get[ $key ] ) ? self::$_get[ $key ] : false;
        if( $xss_clean == true )
            return htmlentities( $get, ENT_QUOTES, 'utf-8' );
        return $get;
    }//end get
    
    /**
     * Get data from POST method.
     * @param string $key
     * @param bool $xss_clean If set to true, class will return xss cleaned data.
     */
    static function post( $key, $xss_clean = false ) {
        $post = isset( self::$_post[ $key ] ) ? self::$_post[ $key ] : false;
        if( $xss_clean == true )
            return htmlentities( $post, ENT_QUOTES, 'utf-8' );
        return $post;
    }//end post
    
    /**
     * Get data from SERVER.
     * @param string $key
     */
    static function server( $key ) {
        $server = isset( self::$_server[ $key ] ) ? self::$_server[ $key ] : false;
        return $server;
    }//end server
    
}